

_realname=notepad++
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=8.8.1
pkgrel=1
pkgdesc="Notepad++ is a free source code editor and Notepad replacement that supports several languages. (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://notepad-plus-plus.org/"
msys2_repository_url="https://github.com/notepad-plus-plus/notepad-plus-plus"
license=("spdx:GPL-3.0-or-later")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-gcc"
  "${MINGW_PACKAGE_PREFIX}-make"
)
options=('!emptydirs')
source=(
  https://github.com/notepad-plus-plus/notepad-plus-plus/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz
  notepad++
  msys2.readme.txt
  msys2.create.portable.sh
  001-aarch64.patch
)
validpgpkeys=('14BCE4362749B2B51F8C71226C429F1D8D84F46E')
sha256sums=('0686000e690d354bb675e85f50c7dfb4691c2dd34fce0f9a57e7a317bb0bd79e'
            'bbb81ac3893a3701cdf6a193666d063b223bffcae4f78bf6e09ad81099ece508'
            'f4468e0fa0e476fc77282cb0b3cff845ed8bce91a816a7c04e8d272abf5c5b1c'
            '2643cce3dbd5fcb65481be4afe7bf6fdea084cde134e04b38dd07239e1f09d59'
            'b8b0ba1750837d771ee3b7fa7e766f220b6e291a0f4f52c07b11e6c5c9fd2750'
)

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd "${srcdir}/notepad-plus-plus-${pkgver}"

  apply_patch_with_msg \
    001-aarch64.patch
}

build() {
  # Build in source dir is mandatory
  cd "${srcdir}"/notepad-plus-plus-${pkgver}
  # Absolute path for makefile is mandatory
  VERBOSE=1 mingw32-make -f "${srcdir}"/notepad-plus-plus-${pkgver}/PowerEditor/gcc/makefile
}

package() {
  SRC_MSYS="${srcdir}"
  SRC_NPP="${srcdir}"/notepad-plus-plus-${pkgver}
  BIN="${srcdir}"/notepad-plus-plus-${pkgver}/bin.${CARCH}
  [ -d "$BIN" ] || BIN=${BIN}-debug

  PKG_BIN="${pkgdir}"/${MINGW_PREFIX}/bin
  mkdir -p "$PKG_BIN" && cd "$PKG_BIN"
  cp -p "$SRC_MSYS"/notepad++ ./

  PKG_LIB="${pkgdir}"/${MINGW_PREFIX}/lib/notepad++
  mkdir -p "$PKG_LIB" && cd "$PKG_LIB"
  cp -rp "$BIN"/* ./
  rm doLocalConf.xml readme.txt change.log

  PKG_DOC="${pkgdir}"/${MINGW_PREFIX}/share/doc/notepad++
  mkdir -p "$PKG_DOC" && cd "$PKG_DOC"
  cp -p "$BIN"/readme.txt "$BIN"/change.log ./
  cp -p "$SRC_MSYS"/msys2.readme.txt "$SRC_MSYS"/msys2.create.portable.sh ./

  PKG_LICENSES="${pkgdir}"/${MINGW_PREFIX}/share/licenses/notepad++
  mkdir -p "$PKG_LICENSES" && cd "$PKG_LICENSES"
  cp -p "$SRC_NPP"/LICENSE license.txt
  cp -p "$SRC_NPP"/lexilla/License.txt license.lexilla.txt
  cp -p "$SRC_NPP"/scintilla/License.txt license.scintilla.txt
}
